package Model.Core.Impl;

import Factory.Entities.StateFactory;
import Factory.Tip.TipsFactory;
import Model.Core.IAchievableState;
import Model.Core.IOriginatorState;
import Model.Core.Tip.Tip;
import Model.Core.Tip.TipMoment;
import Model.Core.Tip.TipType;
import Model.Draw.Events.ManifestStateDoneListener;
import Model.Draw.IMachineStateDraw;
import Model.Draw.IStateDraw;
import java.util.List;

/**
 * Projeto de TCC: Editor de Diagramas de comunicação BlueJ
 * @author Jose
 */
public class State implements IOriginatorState, IAchievableState {

    private IStateDraw draw;
    private StateFactory stateFactory;
    private List<Tip> tips;

    public State() {
        stateFactory = new StateFactory();
        tips = TipsFactory.createStateTips();
    }

    @Override
    public IMachineStateDraw getDraw() {
        return draw;
    }

    @Override
    public void setDraw(IMachineStateDraw draw) {
        this.draw = (IStateDraw) draw;
    }

    @Override
    public void manifestGraphically(Object sourceElement, Object targetElement) {
        stateFactory.createStateGraphicalManifest(this, sourceElement, targetElement);
    }

    @Override
    public void addGraphicalManifestListener(ManifestStateDoneListener listener) {
        stateFactory.addListener(listener);
    }

    @Override
    public void removeGraphicalManifestListener(ManifestStateDoneListener listener) {
        stateFactory.removeListener(listener);
    }

    @Override
    public Tip findTipBy(TipType type, TipMoment moment) {
        for (Tip tip : tips) {
            if (tip.getType() == type && tip.getMoment() == moment) {
                return tip;
            }
        }
        return null;
    }
}